// add_clothes_page.dart
import 'package:flutter/material.dart';
import '../../models/clothes.dart';

class add_clothes_page extends StatefulWidget {
  @override
  _add_clothes_pageState createState() => _add_clothes_pageState();
}

class _add_clothes_pageState extends State<add_clothes_page> {
  final _formKey = GlobalKey<FormState>();
  String _bookmarkTitle = '';
  String _bookmarkUrl = '';

  void _submitForm() {
    // 这里可以添加代码来处理书签信息的保存逻辑
    // 暂时打印到控制台
    print('Title: $_bookmarkTitle, URL: $_bookmarkUrl');
    Navigator.pop(context); // 完成后返回上一页面
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('添加书签')),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Form(
          key: _formKey,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              TextFormField(
                decoration: const InputDecoration(labelText: '标题'),
                validator: (value) {
                  if (value == null || value.isEmpty) {
                    return '请输入标题';
                  }
                  return null;
                },
                onSaved: (value) => _bookmarkTitle = value!,
              ),
              TextFormField(
                decoration: const InputDecoration(labelText: 'URL'),
                keyboardType: TextInputType.url,
                validator: (value) {
                  if (value == null || !value.startsWith('http')) {
                    return '请输入有效的URL';
                  }
                  return null;
                },
                onSaved: (value) => _bookmarkUrl = value!,
              ),
              const SizedBox(height: 16),
              ElevatedButton(
                onPressed: () {
                  if (_formKey.currentState!.validate()) {
                    _formKey.currentState!.save();
                    _submitForm();
                  }
                },
                child: const Text('添加'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
